<template>
	<view class="mainbgc mainpadding">
		<header-top :messageInfo="{typeFlag:true,message:'添加商品',liner:false}">
			<view class="rightmsg" slot="rightmsg">
				<view class="rightmsg_content">
					<view class="nostrongtext" @click="surebtn">确定</view>
				</view>
			</view>
		</header-top>
		<!-- 销内容 -->
		<view class="mainpadding ffffff margin_top" v-for="(item,index) in list" :key="index">
			<view class="flexbetween xiabiank">
				<view class="flexleft">
					<view class="flexleft" v-if="getmsg.type==3">
						<!-- 销 -->
						<view class="icon" v-show="item.type==1" @click="changetype(item)"></view>
						<!-- 退 -->
						<view class="icontow" v-show="item.type==2" @click="changetype(item)"></view>
					</view>
					<view class="titletext">{{item.name}}</view>
				</view>
				<view class="jiahao" @click="add(item,index)"></view>
			</view>
			<view class="flexbuju margin_top" v-if="item.producedate_status==1">
				<view class="huisetext">保质期：</view>
				<input type="number" class="inputs xiabiank" style="text-align: center;" placeholder="保质期天数" disabled=""
					v-model="item.bzq">
				<view class="huisetext">天</view>
			</view>
			<!-- 大单位 -->
			<template v-if="item.biggoodsunit.id">
				<template v-if="item.producedate_status==1">
					<!-- 后台返回生产日期 销售单，采购退货单-->
					<view class="flexbuju margin_top" v-if="getmsg.type==3 || getmsg.type==2"
						@click="getProductTime(item,index,1)">
						<view class="huisetext">生产日期：</view>
						<input type="text" class="inputs xiabiank" style="text-align: center;" placeholder="选择生产日期"
							disabled="" v-model="item.biggoodsunit.produce_time">
						<view class="sanjiaox"></view>
					</view>
					<!-- 自选生产日期 -->
					<view class="flexbuju margin_top" v-else @click="selectTime(index,1)">
						<view class="huisetext">生产日期：</view>
						<input type="text" class="inputs xiabiank" style="text-align: center;" placeholder="选择生产日期"
							disabled="" v-model="item.biggoodsunit.produce_time">
						<view class="sanjiaox"></view>
					</view>
				</template>
				<view class="flexbetween margin_top">
					<input type="number" class="inputsl xiabiank" placeholder="数量" v-model="item.biggoodsunit.num">
					<view class="nostrongtext flexcenter" style="min-width: 100rpx;">{{item.biggoodsunit.name}}</view>
					<input type="number" class="inputsl xiabiank" placeholder="单价" v-model="item.biggoodsunit.price"
						v-if="getmsg.type!=5 && getmsg.type!=7" :disabled="item.allow_gj==1?false:true"  @blur="gaijiaprice(item,'1',index)">

					<input type="number" class="inputsl xiabiank" placeholder="金额" style="margin-right: 10rpx;"
						:value="total_price(item.biggoodsunit.num,item.biggoodsunit.price)" disabled=""
						v-if="getmsg.type!=5 && getmsg.type!=7">
					<input type="text" class="inputsl xiabiank" placeholder="备注" v-model="item.biggoodsunit.notes">
				</view>
				<!-- 赠品信息，销售单可添加赠品（上方按钮如果为退货状态不可以添加赠品） -->
				<view class="flexleft margin_top" v-if="(getmsg.type==3 && item.type==1) || getmsg.type==4">
					<input type="number" class="xiabiank textcontent" placeholder="赠品数"
						v-model="item.biggoodsunit.send_num">
					<view class="nostrongtext flexcenter" style="min-width: 100rpx;">{{item.biggoodsunit.name}}</view>
					<input type="text" class="xiabiank textcontent" placeholder="赠品备注"
						v-model="item.biggoodsunit.send_notes">
				</view>
				<!-- 只有采购退货单，出库单，调拨单判断是否存在库存不足情况 -->
				<view class="flexbetween margin_top" v-if="getmsg.type==2 || getmsg.type==6 || getmsg.type==7">
					<view class="smalltext" :style="{color:Number(item.biggoodsunit.use_stock)>0?'#2cd551' : '#ff0000'}">可用库存：{{item.biggoodsunit.use_stock}}
						<text style="color: #ff0000;margin-left: 5rpx;"
							v-show="Number(item.biggoodsunit.num)>Number(item.biggoodsunit.use_stock)">库存不足</text>
					</view>
				</view>
				<!-- 销售单,退货单显示购买赠送积分 -->
				<view class="flexright margin_top smalltext" style="color: #0BBDCB;"
					v-if="(getmsg.type==3 || getmsg.type==4) && item.biggoodsunit.goods_sku_info.buy_send_score">
					购买赠送积分{{item.biggoodsunit.goods_sku_info.buy_send_score}}</view>
				<!-- 采购单,销售单须显示实际库存可用库存 -->
				<view class="flexbetween margin_top smalltext" v-if="getmsg.type==1 || getmsg.type==3">
					<text style="color: #ff0000;margin-left: 5rpx;"
						v-show="Number(item.biggoodsunit.sj_stock)<0">实际库存：{{item.biggoodsunit.sj_stock}}</text>
					<text style="color: #2cd551;margin-left: 5rpx;"
						v-show="Number(item.biggoodsunit.sj_stock)>0">实际库存：{{item.biggoodsunit.sj_stock}}</text>
					<text style="color: #ff0000;margin-left: 5rpx;"
						v-show="Number(item.biggoodsunit.use_stock)<0">可用库存：{{item.biggoodsunit.use_stock}}</text>
					<text style="color: #2cd551;margin-left: 5rpx;"
						v-show="Number(item.biggoodsunit.use_stock)>0">可用库存：{{item.biggoodsunit.use_stock}}</text>
				</view>
			</template>
			<!-- 中单位 -->
			<template v-if="item.middlegoodsunit.id">
				<template v-if="item.producedate_status==1">
					<!-- 后台返回生产日期 销售单，采购退货单-->
					<view class="flexbuju margin_top" v-if="getmsg.type==3 || getmsg.type==2"
						@click="getProductTime(item,index,2)">
						<view class="huisetext">生产日期：</view>
						<input type="text" class="inputs xiabiank" style="text-align: center;" placeholder="选择生产日期"
							disabled="" v-model="item.middlegoodsunit.produce_time">
						<view class="sanjiaox"></view>
					</view>
					<!-- 自选生产日期 -->
					<view class="flexbuju margin_top" v-else @click="selectTime(index,2)">
						<view class="huisetext">生产日期：</view>
						<input type="text" class="inputs xiabiank" style="text-align: center;" placeholder="选择生产日期"
							disabled="" v-model="item.middlegoodsunit.produce_time">
						<view class="sanjiaox"></view>
					</view>
				</template>
				<view class="flexbetween margin_top">
					<input type="number" class="inputsl xiabiank" placeholder="数量" v-model="item.middlegoodsunit.num">
					<view class="nostrongtext flexcenter" style="min-width: 100rpx;">{{item.middlegoodsunit.name}}
					</view>
					<input type="number" class="inputsl xiabiank" placeholder="单价" v-model="item.middlegoodsunit.price"
						v-if="getmsg.type!=5 && getmsg.type!=7" :disabled="item.allow_gj==1?false:true"  @blur="gaijiaprice(item,'2',index)">

					<input type="number" class="inputsl xiabiank" placeholder="金额" style="margin-right: 10rpx;"
						:value="total_price(item.middlegoodsunit.num,item.middlegoodsunit.price)" disabled=""
						v-if="getmsg.type!=5 && getmsg.type!=7">
					<input type="text" class="inputsl xiabiank" placeholder="备注" v-model="item.middlegoodsunit.notes">
				</view>
				<!-- 赠品信息，销售单可添加赠品（上方按钮如果为退货状态不可以添加赠品） -->
				<view class="flexleft margin_top" v-if="(getmsg.type==3 && item.type==1) || getmsg.type==4">
					<input type="number" class="xiabiank textcontent" placeholder="赠品数"
						v-model="item.middlegoodsunit.send_num">
					<view class="nostrongtext flexcenter" style="min-width: 100rpx;">{{item.middlegoodsunit.name}}
					</view>
					<input type="text" class="xiabiank textcontent" placeholder="赠品备注"
						v-model="item.middlegoodsunit.send_notes">
				</view>
				<!-- 只有采购退货单，出库单，调拨单判断是否存在库存不足情况 -->
				<view class="flexbetween margin_top" v-if="getmsg.type==2 || getmsg.type==6 || getmsg.type==7">
					<view class="smalltext" :style="{color:Number(item.middlegoodsunit.use_stock)>0?'#2cd551' : '#ff0000'}">可用库存：{{item.middlegoodsunit.use_stock}}
						<text style="color: #ff0000;margin-left: 5rpx;"
							v-show="Number(item.middlegoodsunit.num)>Number(item.middlegoodsunit.use_stock)">库存不足</text>
					</view>
				</view>
				<!-- 销售单,退货单显示购买赠送积分 -->
				<view class="flexright margin_top smalltext" style="color: #0BBDCB;"
					v-if="(getmsg.type==3 || getmsg.type==4) && item.middlegoodsunit.goods_sku_info.buy_send_score">
					购买赠送积分{{item.middlegoodsunit.goods_sku_info.buy_send_score}}</view>
				<!-- 采购单,销售单须显示实际库存可用库存 -->
				<view class="flexbetween margin_top smalltext" v-if="getmsg.type==1 || getmsg.type==3">
					<text style="color: #ff0000;margin-left: 5rpx;"
						v-show="Number(item.middlegoodsunit.sj_stock)<0">实际库存：{{item.middlegoodsunit.sj_stock}}</text>
					<text style="color: #2cd551;margin-left: 5rpx;"
						v-show="Number(item.middlegoodsunit.sj_stock)>0">实际库存：{{item.middlegoodsunit.sj_stock}}</text>
					<text style="color: #ff0000;margin-left: 5rpx;"
						v-show="Number(item.middlegoodsunit.use_stock)<0">可用库存：{{item.middlegoodsunit.use_stock}}</text>
					<text style="color: #2cd551;margin-left: 5rpx;"
						v-show="Number(item.middlegoodsunit.use_stock)>0">可用库存：{{item.middlegoodsunit.use_stock}}</text>
				</view>
			</template>
			<!-- 小单位 -->
			<template v-if="item.smallgoodsunit.id">
				<template v-if="item.producedate_status==1">
					<!-- 后台返回生产日期 销售单，采购退货单-->
					<view class="flexbuju margin_top" v-if="getmsg.type==3 || getmsg.type==2"
						@click="getProductTime(item,index,3)">
						<view class="huisetext">生产日期：</view>
						<input type="text" class="inputs xiabiank" style="text-align: center;" placeholder="选择生产日期"
							disabled="" v-model="item.smallgoodsunit.produce_time">
						<view class="sanjiaox"></view>
					</view>
					<!-- 自选生产日期 -->
					<view class="flexbuju margin_top" v-else @click="selectTime(index,3)">
						<view class="huisetext">生产日期：</view>
						<input type="text" class="inputs xiabiank" style="text-align: center;" placeholder="选择生产日期"
							disabled="" v-model="item.smallgoodsunit.produce_time">
						<view class="sanjiaox"></view>
					</view>
				</template>
				<view class="flexbetween margin_top">
					<input type="number" class="inputsl xiabiank" placeholder="数量" v-model="item.smallgoodsunit.num">
					<view class="nostrongtext flexcenter" style="min-width: 100rpx;">{{item.smallgoodsunit.name}}</view>
					<input type="number" class="inputsl xiabiank" placeholder="单价" v-model="item.smallgoodsunit.price"
						v-if="getmsg.type!=5 && getmsg.type!=7" :disabled="item.allow_gj==1?false:true" @blur="gaijiaprice(item,'3',index)">

					<input type="number" class="inputsl xiabiank" placeholder="金额" style="margin-right: 10rpx;"
						:value="total_price(item.smallgoodsunit.num,item.smallgoodsunit.price)" disabled=""
						v-if="getmsg.type!=5 && getmsg.type!=7">
					<input type="text" class="inputsl xiabiank" placeholder="备注" v-model="item.smallgoodsunit.notes">
				</view>
				<!-- 赠品信息，销售单可添加赠品（销售单上方按钮如果为退货状态不可以添加赠品） -->
				<view class="flexleft margin_top" v-if="(getmsg.type==3 && item.type==1) || getmsg.type==4">
					<input type="number" class="xiabiank textcontent" placeholder="赠品数"
						v-model="item.smallgoodsunit.send_num">
					<view class="nostrongtext flexcenter" style="min-width: 100rpx;">{{item.smallgoodsunit.name}}</view>
					<input type="text" class="xiabiank textcontent" placeholder="赠品备注"
						v-model="item.smallgoodsunit.send_notes">
				</view>
				<!-- 只有采购退货单，出库单，调拨单判断是否存在库存不足情况 -->
				<view class="flexbetween margin_top" v-if="getmsg.type==2 || getmsg.type==6 || getmsg.type==7">
					<view class="smalltext" :style="{color:Number(item.smallgoodsunit.use_stock)>0?'#2cd551' : '#ff0000'}">可用库存：{{item.smallgoodsunit.use_stock}}
						<text style="color: #ff0000;margin-left: 5rpx;"
							v-show="Number(item.smallgoodsunit.num)>Number(item.smallgoodsunit.use_stock)">库存不足</text>
					</view>
				</view>
				<!-- 销售单,退货单显示购买赠送积分 -->
				<view class="flexright margin_top smalltext" style="color: #0BBDCB;"
					v-if="(getmsg.type==3 || getmsg.type==4) && item.smallgoodsunit.goods_sku_info.buy_send_score">
					购买赠送积分{{item.smallgoodsunit.goods_sku_info.buy_send_score}}</view>
				<!-- 采购单,销售单须显示实际库存可用库存 -->
				<view class="flexbetween margin_top smalltext" v-if="getmsg.type==1 || getmsg.type==3">
					<text style="color: #ff0000;margin-left: 5rpx;"
						v-show="Number(item.smallgoodsunit.sj_stock)<0">实际库存：{{item.smallgoodsunit.sj_stock}}</text>
					<text style="color: #2cd551;margin-left: 5rpx;"
						v-show="Number(item.smallgoodsunit.sj_stock)>0">实际库存：{{item.smallgoodsunit.sj_stock}}</text>
					<text style="color: #ff0000;margin-left: 5rpx;"
						v-show="Number(item.smallgoodsunit.use_stock)<0">可用库存：{{item.smallgoodsunit.use_stock}}</text>
					<text style="color: #2cd551;margin-left: 5rpx;"
						v-show="Number(item.smallgoodsunit.use_stock)>0">可用库存：{{item.smallgoodsunit.use_stock}}</text>
				</view>
			</template>
			<!-- 按钮 -->
			<view class="flexcenter margin_top">
				<view class="allbtn"
					:class="getmsg.type==1||getmsg.type==2||getmsg.type==3||getmsg.type==4?'shanchu':'shanchu2'"
					@click="deletegoods(index)">删除商品</view>
				<view class="lansebtn allbtn" v-if="getmsg.type==1||getmsg.type==2||getmsg.type==3||getmsg.type==4"
					@click="historyList(item)">历史记录</view>
			</view>
		</view>
		<u-datetime-picker :show="timeshow" mode="date" v-model="value1" title="选择生产日期" @confirm="timersure"
			@cancel="timeshow=false">
		</u-datetime-picker>
		<u-picker :show="timePickershow" :columns="timePickercolumns" @confirm="timePickersure" title="选择生产日期"
			keyName="produce_time_text" @cancel="timePickershow=false"></u-picker>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				timePickershow: false,
				timePickercolumns: [],
				timeshow: false,
				value1: Number(new Date()),
				getmsg: {
					type: 1, //1采购单，
					ids: [6],
					warehouse_id: "",
					custom_id:"",
					supplier_id:"",
				},
				list: [],
				selectindex: "", //选择生产日期下标标识
				selectvalue: "", //选择生产日期大中小单位标识
				rk_id: ''
			}
		},
		onLoad(options) {
			let data = JSON.parse(decodeURIComponent(options.getmsg));
			this.getmsg = data
			console.log(data,"888888");
			this.init()
		},
		methods: {
			gaijiaprice(val1,val2,val3){//判断更改的价格是否小于成本价，最小为进价
				let obj = {
					"1":"biggoodsunit",
					"2":"middlegoodsunit",
					"3":"smallgoodsunit",
				}
				// console.log(val1[obj[val2]].price,"呼呼呼");
				// console.log(this.list[val3][obj[val2]].price,"haihaihai");
				if(Number(val1[obj[val2]].price)<Number(val1[obj[val2]].goods_sku_info.cost_price)){
					this.list[val3][obj[val2]].price = val1[obj[val2]].goods_sku_info.cost_price
				}
			},
			// 界面初始化，获取商品数据
			init() {
				let _this = this;
				let data = {
					ids: this.getmsg.ids.join(),
					custom_id:this.getmsg.custom_id || "",
					supplier_id:this.getmsg.supplier_id || ""
				}
				if(this.getmsg.type == 2 || this.getmsg.type == 3){
					this.$set(data,"warehouse_id",this.getmsg.warehouse_id)
				}
				httpRequest.request('/dhtapi/goods/chooseGoodsList', 'POST', data, false, false, true).then(res => {
					res.data.forEach(item => {
						// 1采购单,2采购退货单3销售单4退货单5入库单6出库单7调拨单
						// 大单位
						if(item.biggoodsunit.goods_sku_info){
							if (this.getmsg.type == 1 || this.getmsg.type == 2 || this.getmsg.type == 5 || this
								.getmsg.type == 7) { // 1采购单,2采购退货单,(5入库单,7调拨单)这俩没用添加价格防止报错
								this.$set(item.biggoodsunit, "price", item.biggoodsunit.goods_sku_info
									.prev_cg_price ? item.biggoodsunit.goods_sku_info.prev_cg_price : item
									.biggoodsunit.goods_sku_info.purchase_price
								) //单价,判断是否存在上次采购价格，存在拿采购价格否则拿进价
							}
							if (this.getmsg.type == 3 || this.getmsg.type == 4 || this.getmsg.type ==
								6) { // 3销售单,4退货单,6出库单
								this.$set(item.biggoodsunit, "price", item.biggoodsunit.goods_sku_info
									.prev_xs_price ? item.biggoodsunit.goods_sku_info.prev_xs_price : item
									.biggoodsunit.goods_sku_info.price) //单价,判断是否存在上次销售价格，存在拿销售价格否则拿进价
							}
							this.$set(item.biggoodsunit, "produce_time", "") // 生产日期
							this.$set(item.biggoodsunit, "notes", "") // 备注
							this.$set(item.biggoodsunit, "num", "") // 数量
							this.$set(item.biggoodsunit, "total_price", "") // 总价
						}
						if(item.middlegoodsunit.goods_sku_info){
							// 中单位
							if (this.getmsg.type == 1 || this.getmsg.type == 2 || this.getmsg.type == 5 || this
								.getmsg.type == 7) { // 1采购单,2采购退货单,(5入库单,7调拨单)这俩没用添加价格防止报错
								this.$set(item.middlegoodsunit, "price", item.middlegoodsunit.goods_sku_info
									.prev_cg_price ? item.middlegoodsunit.goods_sku_info.prev_cg_price :
									item
									.middlegoodsunit.goods_sku_info.purchase_price
								) //单价,判断是否存在上次采购价格，存在拿采购价格否则拿进价
							}
							if (this.getmsg.type == 3 || this.getmsg.type == 4 || this.getmsg.type ==
								6) { // 3销售单,4退货单,6出库单
								this.$set(item.middlegoodsunit, "price", item.middlegoodsunit.goods_sku_info
									.prev_xs_price ? item.middlegoodsunit.goods_sku_info.prev_xs_price :
									item
									.middlegoodsunit.goods_sku_info.price
								) //单价,判断是否存在上次销售价格，存在拿销售价格否则拿进价
							}
							this.$set(item.middlegoodsunit, "produce_time", "") // 生产日期
							this.$set(item.middlegoodsunit, "notes", "") // 备注
							this.$set(item.middlegoodsunit, "num", "") // 数量
							this.$set(item.middlegoodsunit, "total_price", "") // 总价
						}
						
						// 小单位
						if (this.getmsg.type == 1 || this.getmsg.type == 2 || this.getmsg.type == 5 || this
							.getmsg.type == 7) { // 1采购单,2采购退货单,(5入库单,7调拨单)这俩没用添加价格防止报错
							this.$set(item.smallgoodsunit, "price", item.smallgoodsunit.goods_sku_info
								.prev_cg_price ? item.smallgoodsunit.goods_sku_info.prev_cg_price :
								item
								.smallgoodsunit.goods_sku_info.purchase_price
							) //单价,判断是否存在上次采购价格，存在拿采购价格否则拿进价
						}
						if (this.getmsg.type == 3 || this.getmsg.type == 4 || this.getmsg.type ==
							6) { // 3销售单,4退货单,6出库单
							this.$set(item.smallgoodsunit, "price", item.smallgoodsunit.goods_sku_info
								.prev_xs_price ? item.smallgoodsunit.goods_sku_info.prev_xs_price :
								item
								.smallgoodsunit.goods_sku_info.price
							) //单价,判断是否存在上次销售价格，存在拿销售价格否则拿进价
						}
						this.$set(item.smallgoodsunit, "produce_time", "") // 生产日期
						this.$set(item.smallgoodsunit, "notes", "") // 备注
						this.$set(item.smallgoodsunit, "num", "") // 数量
						this.$set(item.smallgoodsunit, "total_price", "") // 总价
						// 销售单，需要展示，赠品
						if (this.getmsg.type == 3 || this.getmsg.type == 4) {
							this.$set(item, "type", 1) // 商品类型，1销售商品，2退货商品
							this.$set(item.biggoodsunit, "send_notes", "") // 赠送备注
							this.$set(item.biggoodsunit, "send_num", "") // 赠送数量
							this.$set(item.middlegoodsunit, "send_notes", "") // 赠送备注
							this.$set(item.middlegoodsunit, "send_num", "") // 赠送数量
							this.$set(item.smallgoodsunit, "send_notes", "") // 赠送备注
							this.$set(item.smallgoodsunit, "send_num", "") // 赠送数量
						}
					})
					this.list = res.data
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			surebtn() {
				let arr = []
				for (let i = 0; i < this.list.length; i++) {
					let item = this.list[i]
					// 如果当前商品的生产日期为必填状态且大中小单位有一个生产日期未填写终止循环，提示选择生产日期
					if (this.getmsg.type == 1 || this.getmsg.type == 2) { //采购单，采购退货单必填生产日期
						if (item.producedate_status == 1 &&
							((item.biggoodsunit.produce_time == '' && item.biggoodsunit.num) ||
								(item.middlegoodsunit.produce_time == '' && item.middlegoodsunit.num) ||
								(item.smallgoodsunit.produce_time == '' && item.smallgoodsunit.num))) {
							httpRequest.toast("请选择" + item.name + "的生产日期")
							return
						}
					}
					// 向数组中添加大中小商品
					if (item.biggoodsunit.num) {
						let biggoodsunitData = {
							goods_id: item.id,
							price: item.biggoodsunit.price,
							num: item.biggoodsunit.num,
							produce_time: item.biggoodsunit.produce_time,
							goods_sku_id: item.biggoodsunit.goods_sku_info.id,
							goods_sku_name: item.biggoodsunit.name,
							notes: item.biggoodsunit.notes,
							goodsinfo: item,
							type: item.type,
							goods_type: 1,
							send_num: item.type == 1 ? item.biggoodsunit.send_num : 0, //判断当前是否是退货商品，如果为退货商品赠送数量为0
							send_notes: item.biggoodsunit.send_notes,
						}
						if (this.getmsg.type == 1 || this.getmsg.type == 2) {
							delete biggoodsunitData.type
							delete biggoodsunitData.goods_type
							delete biggoodsunitData.send_num
							delete biggoodsunitData.send_notes
						} else if (this.getmsg.type == 4) {
							delete biggoodsunitData.type
							delete biggoodsunitData.goods_type
						} else if (this.getmsg.type == 5 || this.getmsg.type == 6 || this.getmsg.type == 7) {
							delete biggoodsunitData.price
							delete biggoodsunitData.type
							delete biggoodsunitData.goods_type
							delete biggoodsunitData.send_num
							delete biggoodsunitData.send_notes
						}
						arr.push(biggoodsunitData)
					}
					if (item.middlegoodsunit.num) {
						let middlegoodsunitData = {
							goods_id: item.id,
							price: item.middlegoodsunit.price,
							num: item.middlegoodsunit.num,
							produce_time: item.middlegoodsunit.produce_time,
							goods_sku_id: item.middlegoodsunit.goods_sku_info.id,
							goods_sku_name: item.middlegoodsunit.name,
							notes: item.middlegoodsunit.notes,
							goodsinfo: item,
							type: item.type,
							goods_type: 1,
							send_num: item.type == 1 ? item.middlegoodsunit.send_num : 0,
							send_notes: item.middlegoodsunit.send_notes,
						}
						if (this.getmsg.type == 1 || this.getmsg.type == 2) {
							delete middlegoodsunitData.type
							delete middlegoodsunitData.goods_type
							delete middlegoodsunitData.send_num
							delete middlegoodsunitData.send_notes
						} else if (this.getmsg.type == 4) {
							delete middlegoodsunitData.type
							delete middlegoodsunitData.goods_type
						} else if (this.getmsg.type == 5 || this.getmsg.type == 6 || this.getmsg.type == 7) {
							delete middlegoodsunitData.price
							delete middlegoodsunitData.type
							delete middlegoodsunitData.goods_type
							delete middlegoodsunitData.send_num
							delete middlegoodsunitData.send_notes
						}
						arr.push(middlegoodsunitData)
					}
					if (item.smallgoodsunit.num ) {
						let smallgoodsunitData = {
							goods_id: item.id,
							price: item.smallgoodsunit.price,
							num: item.smallgoodsunit.num,
							produce_time: item.smallgoodsunit.produce_time,
							goods_sku_id: item.smallgoodsunit.goods_sku_info.id,
							goods_sku_name: item.smallgoodsunit.name,
							notes: item.smallgoodsunit.notes,
							goodsinfo: item,
							type: item.type,
							goods_type: 1,
							send_num: item.type == 1 ? item.smallgoodsunit.send_num : 0,
							send_notes: item.smallgoodsunit.send_notes,
						}
						if (this.getmsg.type == 1 || this.getmsg.type == 2) {
							delete smallgoodsunitData.type
							delete smallgoodsunitData.goods_type
							delete smallgoodsunitData.send_num
							delete smallgoodsunitData.send_notes
						} else if (this.getmsg.type == 4) {
							delete smallgoodsunitData.type
							delete smallgoodsunitData.goods_type
						} else if (this.getmsg.type == 5 || this.getmsg.type == 6 || this.getmsg.type == 7) {
							delete smallgoodsunitData.price
							delete smallgoodsunitData.type
							delete smallgoodsunitData.goods_type
							delete smallgoodsunitData.send_num
							delete smallgoodsunitData.send_notes
						}
						arr.push(smallgoodsunitData)
					}
				}
				if (!arr.length) {
					httpRequest.toast("请至少添加一件商品并输入数量！")
					return false
				}
				if (this.getmsg.type == 1) { //采购单
					let caigoudanInfo = JSON.parse(uni.getStorageSync("caigoudanInfo"))
					let concatarr = caigoudanInfo.data.concat(arr)
					caigoudanInfo.data = caigoudanInfo.data.concat(arr)
					uni.setStorageSync('caigoudanInfo', JSON.stringify(caigoudanInfo))
				}
				if (this.getmsg.type == 2) { //采购退货单
					let caigoutuihuoInfo = JSON.parse(uni.getStorageSync("caigoutuihuoInfo"))
					let concatarr = caigoutuihuoInfo.data.concat(arr)
					caigoutuihuoInfo.data = caigoutuihuoInfo.data.concat(arr)
					uni.setStorageSync('caigoutuihuoInfo', JSON.stringify(caigoutuihuoInfo))
				}
				if (this.getmsg.type == 3) { //销售单
					let xiaoshoudanInfo = JSON.parse(uni.getStorageSync("xiaoshoudanInfo"))
					let concatarr = xiaoshoudanInfo.data.concat(arr)
					xiaoshoudanInfo.data = xiaoshoudanInfo.data.concat(arr)
					uni.setStorageSync('xiaoshoudanInfo', JSON.stringify(xiaoshoudanInfo))
				}
				if (this.getmsg.type == 4) { //退货单
					let tuihuodanInfo = JSON.parse(uni.getStorageSync("tuihuodanInfo"))
					let concatarr = tuihuodanInfo.data.concat(arr)
					tuihuodanInfo.data = tuihuodanInfo.data.concat(arr)
					uni.setStorageSync('tuihuodanInfo', JSON.stringify(tuihuodanInfo))
				}
				if (this.getmsg.type == 5) { //入库单
					let rukudanInfo = JSON.parse(uni.getStorageSync("rukudanInfo"))
					let concatarr = rukudanInfo.data.concat(arr)
					rukudanInfo.data = rukudanInfo.data.concat(arr)
					uni.setStorageSync('rukudanInfo', JSON.stringify(rukudanInfo))
				}
				if (this.getmsg.type == 6) { //出库单
					let chukudanInfo = JSON.parse(uni.getStorageSync("chukudanInfo"))
					let concatarr = chukudanInfo.data.concat(arr)
					chukudanInfo.data = chukudanInfo.data.concat(arr)
					uni.setStorageSync('chukudanInfo', JSON.stringify(chukudanInfo))
				}
				if (this.getmsg.type == 7) { //调拨单
					let diaobodanInfo = JSON.parse(uni.getStorageSync("diaobodanInfo"))
					let concatarr = diaobodanInfo.data.concat(arr)
					diaobodanInfo.data = diaobodanInfo.data.concat(arr)
					uni.setStorageSync('diaobodanInfo', JSON.stringify(diaobodanInfo))
				}
				uni.navigateBack({
					delta: 2
				})
			},
			// 获取生产日期
			getProductTime(item, index, value) {
				this.selectindex = index
				this.selectvalue = value
				uni.showLoading({
					mask: true,
					title: "请稍候。。。"
				})
				httpRequest.request('/dhtapi/Saleorder/getGoodsProduceTime', 'GET', {
					goods_id: item.id,
					warehouse_id: this.getmsg.warehouse_id,
					difference_type: value
				}, false, false, true).then(res => {
					uni.hideLoading()
					this.timePickercolumns = []
					if (res.data.length) {
						this.timePickercolumns.push(res.data.reverse())
						this.timePickershow = true
					} else {
						httpRequest.toast("当前仓库无此类商品！")
					}
				}).catch(err => {})
			},
			// 添加商品数据
			add(item, index) {
				// 添加商品
				let newobj = JSON.parse(JSON.stringify(item))
				// 添加商品之后需要给原有的数量，单价，总价，备注删除
				// 大单位
				newobj.biggoodsunit.price = newobj.biggoodsunit.goods_sku_info.prev_cg_price ? newobj.biggoodsunit
					.goods_sku_info.prev_cg_price : newobj.biggoodsunit.goods_sku_info.purchase_price
				newobj.biggoodsunit.produce_time = ""
				newobj.biggoodsunit.notes = ""
				newobj.biggoodsunit.num = ""
				newobj.biggoodsunit.total_price = ""
				//中单位
				newobj.middlegoodsunit.price = newobj.middlegoodsunit.goods_sku_info.prev_cg_price ? newobj.middlegoodsunit
					.goods_sku_info.prev_cg_price : newobj.middlegoodsunit.goods_sku_info.purchase_price
				newobj.middlegoodsunit.produce_time = ""
				newobj.middlegoodsunit.notes = ""
				newobj.middlegoodsunit.num = ""
				newobj.middlegoodsunit.total_price = ""
				// 小单位
				newobj.smallgoodsunit.price = newobj.smallgoodsunit.goods_sku_info.prev_cg_price ? newobj.smallgoodsunit
					.goods_sku_info.prev_cg_price : newobj.smallgoodsunit.goods_sku_info.purchase_price
				newobj.smallgoodsunit.produce_time = ""
				newobj.smallgoodsunit.notes = ""
				newobj.smallgoodsunit.num = ""
				newobj.smallgoodsunit.total_price = ""
				this.list.push(newobj)
			},
			// 选择生产日期
			selectTime(index, value) {
				this.selectindex = index
				this.selectvalue = value
				this.timeshow = true
			},
			timersure(e) {
				let obj = {
					"1": "biggoodsunit",
					"2": "middlegoodsunit",
					"3": "smallgoodsunit"
				}

				this.list[this.selectindex][obj[this.selectvalue]].produce_time = this.date(e.value)
				this.timeshow = false
			},
			timePickersure(e) {
				let obj = {
					"1": "biggoodsunit",
					"2": "middlegoodsunit",
					"3": "smallgoodsunit"
				}
				this.list[this.selectindex][obj[this.selectvalue]].produce_time = e.value[0].produce_time_text
				this.timePickershow = false
			},
			// 删除商品
			deletegoods(index) {
				this.list.splice(index, 1)
			},
			// 历史记录
			historyList(item) {
				let data = {
					goods_id: item.id,
					type: this.getmsg.type,
				}
				uni.navigateTo({
					url: '/pages/workbench/xiaoshou/dingdanxiaoshoulis?data=' + encodeURIComponent(JSON.stringify(
						data))
				})
			},
			// 切换商品状态值
			changetype(item) {
				item.type = item.type == 1 ? 2 : 1
			},
			//日期加上天数得到新的日期
			// //dateTemp 需要参加计算的日期，days要添加的天数，返回新的日期，日期格式：YYYY-MM-DD
			// getNewDay(dateTemp, days) {
			//     var dateTemp = dateTemp.split("-");
			//     var nDate = new Date(dateTemp[1] + '-' + dateTemp[2] + '-' + dateTemp[0]); //转换为MM-DD-YYYY格式  
			//     var millSeconds = Math.abs(nDate) + (days * 24 * 60 * 60 * 1000);
			//     var rDate = new Date(millSeconds);
			//     var year = rDate.getFullYear();
			//     var month = rDate.getMonth() + 1;
			//     if (month < 10) month = "0" + month;
			//     var date = rDate.getDate();
			//     if (date < 10) date = "0" + date;
			//     return (year + "-" + month + "-" + date);
			// },
			total_price(val1, val2) {
				return val1 * val2
			},
			date(timer) {
				var date = new Date(timer); //当前时间
				var year = date.getFullYear() //返回指定日期的年份
				var month = repair(date.getMonth() + 1); //月
				var day = repair(date.getDate()); //日
				var curTime = year + "-" + month + "-" + day

				function repair(i) {
					if (i >= 0 && i <= 9) {
						return "0" + i;
					} else {
						return i;
					}
				}
				return curTime
			},


		}
	}
</script>

<style lang="scss" scoped>
	.mainbgc {
		background-color: #FAFAFA;
		min-height: calc(100vh - 100rpx);

	}

	.xiaohuitext {
		font-size: 22rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.textcontent {
		text-align: center;
	}

	.nostrongtext {
		padding-bottom: 20rpx;
	}

	.allbtn {
		border-radius: 43rpx;
		padding: 10rpx 50rpx;
		border: 2rpx solid #E7E7E7;
	}

	.lansebtn {
		border-radius: 0 43rpx 43rpx 0;
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #0BBDCB;
	}

	.shanchu {
		border-radius: 43rpx 0 0 43rpx;
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
		border-right: none;
	}

	.shanchu2 {
		border-radius: 43rpx;
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.smalltext {
		font-size: 22rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.sanjiaox {
		border: 14rpx solid transparent;
		border-top: 14rpx solid #666666;
	}

	.inputsl {
		width: 25%;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		text-align: center;
	}

	.flexbuju {
		display: flex;
		align-items: flex-start;
	}

	.inputs {
		width: 40%;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
	}

	.huisetext {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.icon {
		background-image: url('@/static/image/system/xiao.png');
		width: 108rpx;
		height: 52rpx;
		margin-right: 34rpx;
		background-size: 100% 100%;
	}

	.icontow {
		background-image: url('@/static/image/system/tui.png');
		width: 108rpx;
		height: 52rpx;
		margin-right: 34rpx;
		background-size: 100% 100%;
	}

	.jiahao {
		width: 43.33rpx;
		height: 43.33rpx;
		background-image: url('@/static/image/system/jiahao.png');
		background-size: 100% 100%;
	}

	.xiabiank {
		padding-bottom: 20rpx;
		border-bottom: 2rpx solid rgba(0, 0, 0, 0.03);
	}
</style>